<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'', styles:'bootstrap,font-awesome,animate,style,bootstrap-table,layui-date,auto-complete,dtvalidate,layui,chosen'}){%>
    <style type="text/css">
        body{padding-top:10px;}
        *{margin:0;padding:0;list-style-type:none;}
        a,img{border:0;}
        .demo h2{font-size:16px;color:#3366cc;height:30px;}
        .demo li{float:left;}
        .has-no{color:#3366cc;}
        .has-success{color: #1ab394;}
        .has-warning{color: #f8ac59;}
        .has-error{color: #ed5565;}
        .has-receive{color: #9E792E;}
        .remark {
            width: 100%; /*自动适应父布局宽度*/
            overflow: auto;
            word-break: break-all;
        }
    </style>
    <%}%>
</head>

<body>
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox-content" style="padding:15px 20px 0px 20px;">
                <form id="search-form" role="form" class="form-horizontal" autocomplete="off">
                    <div class="form-group">
                        <label class="control-label col-sm-1">状态:</label>
                        <div class="col-sm-2">
                            <select  name="produceStatus" id="produceStatus" class="form-control">
                                <option value="">全部分类</option>
                                <option value="1">待审核</option>
                                <option value="2">审核中</option>
                                <option value="3">审核通过</option>
                                <option value="4">拒绝</option>
                                <option value="5">废弃</option>
                                <option value="31">部分收货</option>
                                <option value="32">全部收货</option>
                                <option value="33">手工关闭</option>
                            </select>
                        </div>
                        <label class="control-label col-sm-1">供应商:</label>
                        <div class="col-sm-2">
                            <input type="text" id="produceSupplierName" name="produceSupplierName" class="form-control">
                        </div>
                        <label class="control-label col-sm-1">PO号:</label>
                        <div class="col-sm-2">
                            <input type="text" id="produceNo" name="produceNo" class="form-control">
                        </div>
                        <label class="control-label col-sm-1">渠道:</label>
                        <div class="col-sm-2">
                            <input type="text" id="produceChannelName" name="produceChannelName" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">

                        <label class="control-label col-sm-1">合同号:</label>
                        <div class="col-sm-2">
                            <input type="text" name="produceAgreement" class="form-control">
                        </div>
                        <label class="control-label col-sm-1">开始时间:</label>
                        <div class="col-sm-2">
                            <input type="text" name="beginDate" id="beginDate" placeholder="请选择开始时间" class="form-control">
                        </div>
                        <label class="control-label col-sm-1">结束时间:</label>
                        <div class="col-sm-2">
                            <input type="text" name="endDate" id="endDate" placeholder="请选择结束时间" class="form-control">
                        </div>

                        <button id="downloadBtn" style="display: none">Download File</button>
                        <a class="search-btn btn btn-success" style="margin-bottom: 0px;">查询</a>
                    </div>
                </form>
            </div>
            <div id="toolbar" class="btn-group" style="margin-bottom:5px;">

                <button  class="export-btn layui-btn  layui-btn-sm" style="margin-top: -6px;margin-left: -2px">
                    <i class="fa fa-download" aria-hidden="true"></i> 导出当前数据
                </button>
                <button  class="layui-btn layui-btn-sm import-btn btn-warning" style="margin-top: -6px;margin-left: -4px" id="import-produceAgreement-btn"  name="import-produceAgreement-btn">
                    <i class="layui-icon"></i>
                    批量导入合同
                </button>

            </div>

    <!-- START 数据表格 -->
    <table id="portTable"
           data-toolbar="#toolbar"
           data-side-pagination="server"
           data-pagination="true"
           data-resizable="true"
           data-url="/sea/supply/produce/findByCnd.do"
           data-page-size="15"
           class="table table-striped table-hover"
    >
    </table>
        </div>
    </div>
    <!-- END 数据表格 -->
</div>


<div id="layer_window" style="display: none;overflow-x: hidden;overflow-y: hidden">
    <!-- START 内容部分 -->
    <div class="container" >
        <form class="form-horizontal" id="info-form" method="post" autocomplete="off" style="margin: auto">
            <input type="hidden" id="id" name="id">
            <input type="hidden" id="produceId" name="produceId">
            <input type="hidden" id="buyId" name="buyId">
            <div class="form-group" style="margin-top: 20px">
                <label class="category control-label col-sm-2" style="max-width: 100px">SKU</label>
                <div class="col-sm-6" style="max-width: 300px">
                    <input type="text" id="orderSku" name="orderSku" readonly value="" class="form-control">
                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="category control-label col-sm-2" style="max-width: 100px">采购总量</label>
                <div class="col-sm-6" style="max-width: 300px">
                    <input type="text" id="produceTotal" name="produceTotal" value="" class="form-control"><label style="color: red">*采购总量不能超过待采购数量</label>
                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="category control-label col-sm-2" style="max-width: 100px">含税单价</label>
                <div class="col-sm-6" style="max-width: 300px">
                    <input type="text" id="producePrice" name="producePrice" value="" class="form-control">
                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="category control-label col-sm-2" style="max-width: 100px">不含税单价</label>
                <div class="col-sm-6" style="max-width: 300px">
                    <input type="text" id="produceUnitPrice" name="produceUnitPrice" value="" class="form-control">
                </div>
            </div>

            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-7" style="max-width: 100px"></label>
                <button type="button" class="save-btn btn btn-primary">
                    <i class="fa fa-save"></i> 保存
                </button>
            </div>
        </form>
    </div>
    <!-- END 内容部分 -->
</div>


<div id="layer_check_window" style="display: none;overflow-x: hidden;overflow-y: hidden">
    <!-- START 内容部分 -->
    <div class="container" >
        <form class="form-horizontal" id="info-form_check" method="post" autocomplete="off" style="margin: auto">
            <input type="hidden" id="produce_id" name="produceId">
            <div class="form-group" style="margin-top: 15px">
                <label class="category control-label col-sm-2" style="max-width: 100px">状态</label>
                <div class="col-sm-6" style="max-width: 300px">
                    <label class="radio-inline" style="padding-top: 9px;">
                        <input type="radio" style="margin-top: 4px;"  name="orderStatus" id="optionsRadios3" value="3" checked> 审核通过
                    </label>
                    <label class="radio-inline" style="padding-top: 9px;">
                        <input type="radio" style="margin-top: 4px;" name="orderStatus" id="optionsRadios4"  value="4"> 拒绝
                    </label>
                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="category control-label col-sm-2" style="max-width: 100px">备注</label>
                <div class="col-sm-6" style="max-width: 400px;">
                    <textarea id="produceRemark" name="produceRemark" class="remark form-control" rows="7"></textarea>
                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-7" style="max-width: 100px"></label>
                <button type="button" class="save-check-btn btn btn-primary">
                    <i class="fa fa-save"></i> 保存
                </button>
            </div>
        </form>
    </div>
    <!-- END 内容部分 -->
</div>

<div id="layer_pay_window" style="display: none;overflow-x: hidden;overflow-y: hidden">
    <!-- START 内容部分 -->
    <div class="container" >
        <form class="form-horizontal" id="info-pay_check" method="post" autocomplete="off" style="margin: auto">
            <input type="hidden" id="pay_produce_id" name="produceId">

            <div class="form-group" style="margin-top: 20px">
                <label class="category control-label col-sm-2" style="max-width: 100px">预付款</label>
                <div class="col-sm-6" style="max-width: 400px;">
                    <input type="text" id="producePayment" name="producePayment" class="form-control" />
                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-7" style="max-width: 100px"></label>
                <button type="button" class="save-pay-btn btn btn-primary">
                    <i class="fa fa-save"></i> 保存
                </button>
            </div>
        </form>
    </div>
    <!-- END 内容部分 -->
</div>


<div id="layer_agreement_window" style="display: none;overflow-x: hidden;overflow-y: hidden">
    <!-- START 内容部分 -->
    <div class="container" >
        <form class="form-horizontal" id="info-agreement-form" method="post" autocomplete="off" style="margin: auto">
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-2" style="max-width: 100px">账期</label>
                <div class="col-sm-6" style="max-width: 300px">
                    <input type="text" id="supplierDay" name="supplierDay" value="" class="form-control">
                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-2" style="max-width: 100px">合同号</label>
                <div class="col-sm-6" style="max-width: 300px">
                    <input type="text" id="produceAgreement" name="produceAgreement" value="" class="form-control">
                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-2" style="max-width: 100px">合同号附件</label>
                <div class="col-sm-6" style="max-width: 300px">
                    <button  class="layui-btn layui-btn-sm import-btn" style="margin-left: -2px" type="button" id="import-btn"  name="import-btn">
                        <i class="layui-icon"></i>导入合同附件
                    </button>
                    <input type="hidden" id="produceAgreementFile" name="produceAgreementFile">
                </div>
            </div>
            <input type="hidden" name="id" id="agreementId">
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-7" style="max-width: 100px"></label>
                <button type="button" class="save-agreement-btn btn btn-primary">
                    <i class="fa fa-save"></i> 保存
                </button>
            </div>
        </form>
    </div>
    <!-- END 内容部分 -->
</div>

<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,bootstrap-table,dtvalidate,dtvalidate-lang-zh_cn,bootstrap-table-zh-CN,laydate,layer,chosen,chosen-demo,layui,upload'}){}%>
<script>
    laydate.render({
        elem: '#buyOrderDate' //指定元素
        ,trigger: 'click'
    });
    laydate.render({
        elem: '#beginDate' //指定元素
        ,trigger: 'click'
    });
    laydate.render({
        elem: '#endDate' //指定元素
        ,trigger: 'click'
    });

    layui.use('upload', function(){
        var upload = layui.upload;
        upload.render({
            elem: '#import-produceAgreement-btn', //绑定元素,
            accept:'file',
            url: '/sea/supply/produce/importProduceAgreement/', //上传接口
            data:{},
            before:function () {
                layer.load(1, {
                    shade: [0.1,'#fff'] //0.1透明度的白色背景
                });
            }
            ,done: function(data){
                if( data.ok ){
                    layer.msg(data.msg,{icon: 1,time: 1500},function(){
                        //刷新页面
                        $portTable.bootstrapTable('refresh');
                        layer.closeAll();
                    });
                }else{
                    layer.msg(data.msg,{icon: 0,btn: ['确定'],time:0,shade: [0.8, '#393D49'],yes: function(index, layero){ // 默认的是 按钮一
                            layer.closeAll();
                        }});

                }
            }
            ,error: function(){
                //请求异常回调
                layer.closeAll();
            }
        });
    });

    var $portTable = $('#portTable');
    $(function(){
        //START 表格配置
        $portTable.bootstrapTable({
            detailView: true,
            pageList: [10, 15, 20, 2000],
            columns: [
                {
                    field: 'state',
                    checkbox: true,
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '采购单号',
                    field: 'produceNo',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '采购渠道',
                    field: 'produceChannelName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '供应商',
                    field: 'produceSupplierName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '采购总量',
                    field: 'produceTotal',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '币种',
                    field: 'produceMoneyType',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '采购总价',
                    field: 'produceTotalMoney',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '支付方式',
                    field: 'paymentType',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '采购剩余',
                    field: 'produceSurplus',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '已收货量',
                    field: '',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v,r) {
                        return r.produceTotal-r.produceSurplus;
                    }
                },
                {
                    title: '合同号',
                    field: 'produceAgreement',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '合同附件',
                    field: 'produceAgreementFile',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v,r) {
                        if(null!=v && v!=''){
                            var result='<button  class="download-btn layui-btn  layui-btn-sm"  style="margin-top: -6px;margin-left: -4px">';
                            result+='<i class="fa fa-download" aria-hidden="true"></i> <a href="'+v+'" download style="color: white">下载附件</a>';
                            result+='</button>';
                            return result;
                        }else{
                            return '';
                        }
                    }
                },
                {
                    title: '账期',
                    field: 'supplierDay',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '创建时间',
                    field: 'createTime',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v,r) {
                        if (v == null) {
                            return '';
                        }
                        v = v.substr(0, 11);
                        return v;
                    }
                },
                {
                    title: '状态',
                    field: 'produceStatus',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v,r) {
                        switch (v) {
                            case 1:
                                return '<label class="control-label has-no"><i class="fa fa-circle" aria-hidden="true"></i> 未审核</label>';
                                break;
                            case 2:
                                return '<label class="control-label has-warning"><i class="fa fa-circle" aria-hidden="true"></i> 审核中</label>';
                                break;
                            case 3:
                                return '<label class="control-label has-success"><i class="fa fa-circle" aria-hidden="true"></i> 审核通过</label>';
                                break;
                            case 4:
                                return '<label class="control-label has-error"><i class="fa fa-circle" aria-hidden="true"></i> 拒绝</label>';
                                break;
                            case 5:
                                return '<label class="control-label has-error"><i class="fa fa-circle" aria-hidden="true"></i> 作废</label>';
                                break;
                            case 31:
                                return '<label class="control-label has-receive"><i class="fa fa-circle" aria-hidden="true"></i> 部分收货</label>';
                                break;
                            case 32:
                                return '<label class="control-label has-receive"><i class="fa fa-circle" aria-hidden="true"></i> 全部收货</label>';
                                break;
                            case 33:
                                return '<label class="control-label has-error"><i class="fa fa-circle" aria-hidden="true"></i> 手工关闭</label>';
                                break;
                            case 34:
                                return '<label class="control-label has-error"><i class="fa fa-circle" aria-hidden="true"></i> 未收关闭</label>';
                                break;
                        }
                    }
                },
                {
                    field: 'operate',
                    title: '操作',
                    align: 'center',
                    valign: 'middle',
                    formatter: optFormatter
                }
            ],
            onLoadSuccess : function(){

                $('.export-fl-btn').on('click',function () {
                    var produceId=$(this).attr("data-val");
                    $.ajax({
                        url: "/sea/operate/related/materialDetail/checkMaterialDetail.do?produceId="+produceId,
                        type: "post",
                        success: function (data) {

                            if (data.ok) {
                                layer.closeAll();
                            } else {
                                layer.confirm(data.msg+"是否继续下载辅料信息?", {
                                    btn: ['确定', '取消'] //可以无限个按钮
                                    ,
                                }, function(index, layero){
                                    var index= layer.load(2, { //icon支持传入0-2
                                        shade: [0.1, '#fff'], //0.5透明度的灰色背景
                                        content: '正在生成压缩包,请稍后...',
                                        success: function (layero) {
                                            layero.find('.layui-layer-content').css({
                                                'padding-top': '39px',
                                                'margin-left': '-50px',
                                                'width': '300px',
                                                'font-color': 'red',
                                                'font-size': '20px'
                                            });
                                        }
                                    });
                                    $.ajax({
                                        url: "/sea/operate/related/materialDetail/downloadMaterialDetail.do?produceId="+produceId,
                                        type: "post",
                                        success: function (data) {
                                            if (data.ok) {
                                                var link = document.createElement('a');
                                                link.href = data.msg;
                                                link.setAttribute('target', '_blank');
                                                link.setAttribute('download', '');
                                                link.download = ''; // 可选：如果设置文件名，可以在此指定
                                                document.body.appendChild(link);
                                                link.click();
                                                document.body.removeChild(link);
                                                layer.closeAll();
                                            } else {
                                                layer.msg(data.msg, {
                                                    icon: 0, btn: ['确定'], time: 0, shade: [0.8, '#393D49'], yes: function (index, layero) { // 默认的是 按钮一
                                                        layer.closeAll();
                                                    }
                                                });
                                            }
                                        },
                                    });
                                }, function(index){

                                });
                            }
                        },
                    });
                });
                $('.export-fnsku-btn').on('click',function () {
                    var produceId=$(this).attr("data-val");
                    var index= layer.load(2, { //icon支持传入0-2
                        shade: [0.1, '#fff'], //0.5透明度的灰色背景
                        content: '正在生成压缩包,请稍后...',
                        success: function (layero) {
                            layero.find('.layui-layer-content').css({
                                'padding-top': '39px',
                                'margin-left': '-50px',
                                'width': '300px',
                                'font-color': 'red',
                                'font-size': '20px'
                            });
                        }
                    });
                    $.ajax({
                        url: "/sea/operate/related/materialDetail/exportFnSku.do?produceId="+produceId,
                        type: "post",
                        success: function (data) {

                            if (data.ok) {
                                var link = document.createElement('a');
                                link.href = data.msg;
                                link.setAttribute('target', '_blank');
                                link.setAttribute('download', '');
                                link.download = ''; // 可选：如果设置文件名，可以在此指定
                                document.body.appendChild(link);
                                link.click();
                                document.body.removeChild(link);
                                layer.closeAll();
                            } else {
                                layer.msg(data.msg, {
                                    icon: 0, btn: ['确定'], time: 0, shade: [0.8, '#393D49'], yes: function (index, layero) { // 默认的是 按钮一
                                        layer.closeAll();
                                    }
                                });
                            }
                        },
                    });
                });
                $('.send-btn').on('click',function(){
                    var id = $(this).attr('data-val');
                    var day = $(this).attr('data-day');
                    $('#agreementId').val(id);
                    if(day=='null' || null==day){
                        $('#supplierDay').val(0);
                    }else {
                        $('#supplierDay').val(day);
                    }
                    layer.open({
                        type:1,
                        title:'确认合同号',
                        area:['600px','300px'],
                        skin:'layui-layer-lan',//layui-layer-molv ;layui-layer-lan;layui-layer-rim;layer-window
                        shadeClose:false,
                        resize: false,
                        scrollbar: false,
                        maxmin: false,//出现最大化按钮
                        content:$('#layer_agreement_window')
                    })
                });
                //删除数据字典详情信息
                $('.del-btn').on('click',function(){
                    var delid = $(this).attr('data-val'),delname = $(this).attr('data-val-no');
                    //删除提示
                    layer.confirm('确定要作废当前采购单？<br>['+delname+']', {
                        btn: ['确定','取消'],title:'提示'
                    }, function(){
                        $.post('/sea/supply/produce/usave.do',{id: delid,produceStatus:5},function(data){
                            if( data.ok ){
                                layer.msg(data.msg,{icon: 1,time: 1500},function(){
                                    //刷新页面
                                    $portTable.bootstrapTable('refresh');
                                });
                            }else{
                                layer.msg(data.msg,{icon: 0,time: 1500});
                            }
                        });
                    });
                });

                //删除数据字典详情信息
                $('.close-btn').on('click',function(){
                    var delid = $(this).attr('data-val'),delname = $(this).attr('data-val-no'),number=$(this).attr('data-val-number');
                    //删除提示
                    layer.confirm('确定要关闭当前采购单,采购剩余'+number+'？<br>['+delname+']', {
                        btn: ['确定','取消'],title:'提示'
                    }, function(){
                        $.post('/sea/supply/produce/usave.do',{id: delid,produceStatus:33},function(data){
                            if( data.ok ){
                                layer.msg(data.msg,{icon: 1,time: 1500},function(){
                                    //刷新页面
                                    $portTable.bootstrapTable('refresh');
                                });
                            }else{
                                layer.msg(data.msg,{icon: 0,time: 1500});
                            }
                        });
                    });
                });

                //删除数据字典详情信息
                $('.receive-close-btn').on('click',function(){
                    var delid = $(this).attr('data-val'),delname = $(this).attr('data-val-no'),number=$(this).attr('data-val-number');
                    //删除提示
                    layer.confirm('确定要关闭当前采购单,采购剩余'+number+'？<br>['+delname+']', {
                        btn: ['确定','取消'],title:'提示'
                    }, function(){
                        $.post('/sea/supply/produce/usave.do',{id: delid,produceStatus:34},function(data){
                            if( data.ok ){
                                layer.msg(data.msg,{icon: 1,time: 1500},function(){
                                    //刷新页面
                                    $portTable.bootstrapTable('refresh');
                                });
                            }else{
                                layer.msg(data.msg,{icon: 0,time: 1500});
                            }
                        });
                    });
                });

                $('.detail-btn').on('click',function(){
                    var id = $(this).attr('data-val');
                    layer.open({
                        type: 2,
                        area: ['700px','500px'],
                        content: ['/sea/supply/record/main.do?id='+id, 'yes']
                    });
                });
                //审核
                $('.pass-btn').on('click',function(){
                    var id = $(this).attr('data-val');
                    var orderNo=$(this).attr('data-val-no');
                    layer.confirm('一经提交审核,无法取消,是否提交【'+orderNo+'】？', {
                        btn: ['确定','取消'],title:'提示'
                    }, function(){
                        layer.closeAll();
                        layer.load();
                        $.post('/sea/supply/produce/usave.do',{id: id,produceStatus:2},function(data){
                            if( data.ok ){
                                layer.msg(data.msg,{icon: 1,time: 1500},function(){
                                    //刷新页面
                                    $portTable.bootstrapTable('refresh');
                                });
                            }else{
                                layer.msg(data.msg,{icon: 0,time: 1500});
                            }
                        });
                        layer.closeAll();
                    });
                });

                //审核
                $('.receive-btn').on('click',function(){
                    var id = $(this).attr('data-val');
                    var orderNo=$(this).attr('data-val-no');
                    layer.confirm('一经收货,无法取消,是否全部收货【'+orderNo+'】？', {
                        btn: ['确定','取消'],title:'提示'
                    }, function(){
                        layer.closeAll();
                        layer.load();
                        $.post('/sea/supply/produce/usave.do',{id: id,produceStatus:32},function(data){
                            if( data.ok ){
                                layer.msg(data.msg,{icon: 1,time: 1500},function(){
                                    //刷新页面
                                    $portTable.bootstrapTable('refresh');
                                });
                            }else{
                                layer.msg(data.msg,{icon: 0,time: 1500});
                            }
                        });
                        layer.closeAll();
                    });
                });

                //新增
                $('.check-btn').on('click',function(){//新增
                    var id = $(this).attr('data-val');
                    $("#produce_id").val(id);
                    layer.open({
                        type:1,
                        title:'审批',
                        area:['600px','450px'],
                        skin:'layui-layer-lan',//layui-layer-molv ;layui-layer-lan;layui-layer-rim;layer-window
                        shadeClose:false,
                        resize: false,
                        scrollbar: false,
                        maxmin: false,//出现最大化按钮
                        content:$('#layer_check_window')
                    })
                });
                //新增
                $('.pay-btn').on('click',function(){//新增
                    var id = $(this).attr('data-val');
                    $("#pay_produce_id").val(id);
                    layer.open({
                        type:1,
                        title:'预付款',
                        area:['600px','450px'],
                        skin:'layui-layer-lan',//layui-layer-molv ;layui-layer-lan;layui-layer-rim;layer-window
                        shadeClose:false,
                        resize: false,
                        scrollbar: false,
                        maxmin: false,//出现最大化按钮
                        content:$('#layer_pay_window')
                    })
                });

                //回滚
                $('.rollback-btn').on('click',function(){
                    var id = $(this).attr('data-val');
                    var orderNo=$(this).attr('data-val-no');
                    layer.confirm('一经回滚,无法取消,是否提交【'+orderNo+'】？', {
                        btn: ['确定','取消'],title:'提示'
                    }, function(){
                        layer.closeAll();
                        layer.load();
                        $.post('/sea/supply/produce/rollback.do',{id: id},function(data){
                            if( data.ok ){
                                layer.msg(data.msg,{icon: 1,time: 1500},function(){
                                    //刷新页面
                                    $portTable.bootstrapTable('refresh');
                                });
                            }else{
                                layer.msg(data.msg,{icon: 0,time: 1500});
                            }
                        });
                        layer.closeAll();
                    });
                });
                $('.pass-btn').on('click',function(){
                    var id = $(this).attr('data-val');
                    var orderNo=$(this).attr('data-val-no');
                    layer.confirm('一经提交审核,无法取消,是否提交【'+orderNo+'】？', {
                        btn: ['确定','取消'],title:'提示'
                    }, function(){
                        layer.closeAll();
                        layer.load();
                        $.post('/sea/supply/produce/usave.do',{id: id,produceStatus:2},function(data){
                            if( data.ok ){
                                layer.msg(data.msg,{icon: 1,time: 1500},function(){
                                    //刷新页面
                                    $portTable.bootstrapTable('refresh');
                                });
                            }else{
                                layer.msg(data.msg,{icon: 0,time: 1500});
                            }
                        });
                        layer.closeAll();
                    });
                });
            },
            onExpandRow: function (index, row, $detail) {
                InitSubTable(index, row, $detail);
            }
        });

        var cur_table;
        var produceStatus;
        function InitSubTable (index, row, $detail) {
            var parentId = row.id;
            produceStatus=row.produceStatus;
            cur_table = $detail.html('<table id="child_table" class="table table-striped table-hover"></table>').find('table');
            $(cur_table).bootstrapTable({
                url: '/sea/supply/produceDetail/findByProduceId',
                method: 'get',
                clickToSelect: true,
                queryParams: { produceId: parentId },
                ajaxOptions: { produceId: parentId },
                //height: 500,
                uniqueId: "id",
                pageSize: 10,
                pageList: [10, 25],
                columns: [
                    {
                        field: 'orderChannelName',
                        title: '渠道',
                        align: 'center'
                    },
                    {
                        field: 'orderSku',
                        title: 'SKU',
                        align: 'center'
                    },
                    {
                        field: 'productName',
                        title: '产品名称',
                        align: 'center'
                    },
                    {
                        field: 'productColorName',
                        title: '产品颜色',
                        align: 'center'
                    },
                    {
                        field: 'productCm',
                        title: '尺码(CM)',
                        align: 'center'
                    },
                    {
                        field: 'productInch',
                        title: '尺码(INCH)',
                        align: 'center'
                    },
                    {
                        field: 'producePrice',
                        title: '含税单价',
                        align: 'center'
                    },
                    {
                        field: 'produceUnitPrice',
                        title: '不含税单价',
                        align: 'center'
                    },{

                        field: 'produceTotal',
                        title: '采购总量',
                        align: 'center'
                    },
                    {
                        field: 'produceSurplus',
                        title: '采购剩余',
                        align: 'center'
                    },
                    {
                        title: '短装数量',
                        field: 'produceShort',
                        align: 'center',
                        valign: 'middle'
                    },
                    {
                        title: '已收货量',
                        field: '',
                        align: 'center',
                        valign: 'middle',
                        formatter:function (v,r) {
                            return r.produceTotal-r.produceSurplus;
                        }
                    },
                    {
                        field: 'buyOrderDate',
                        title: '预计交期',
                        align: 'center'
                    },
                    {
                        field: 'productPackageNumber',
                        title: '装箱量',
                        align: 'center'
                    },
                    {
                        field: 'boxNumber',
                        title: '箱数',
                        align: 'center'
                    },
                    {
                        field: 'flag',
                        title: '关闭',
                        align: 'center',
                        formatter:function (v,r) {
                            if(v==1){
                                return '是'
                            }else {
                                return '否'
                            }
                        }
                    },
                    {
                        field: 'operate',
                        title: '操作',
                        align: 'center',
                        valign: 'middle',
                        formatter: optFormatter2
                    }],
                onLoadSuccess : function(){
                    $('.edit-btn').on('click',function () {
                        var id = $(this).attr('data-val');
                        $("#id").val(id);
                        var sku=$(this).attr('data-sku');
                        $("#orderSku").val(sku);
                        var total=$(this).attr('data-total');
                        $("#produceTotal").val(total);
                        var price=$(this).attr('data-price');
                        $("#producePrice").val(price);
                        var unitPrice=$(this).attr('data-unit-price');
                        $("#produceUnitPrice").val(unitPrice);
                        var produceId=$(this).attr('data-produce-id');
                        $("#produceId").val(produceId);
                        var buyId=$(this).attr('data-buy-id');
                        $("#buyId").val(buyId);
                        layer.open({
                            type:1,
                            title:'修改请购单明细',
                            area:['600px','370px'],
                            skin:'layui-layer-lan',//layui-layer-molv ;layui-layer-lan;layui-layer-rim;layer-window
                            shadeClose:false,
                            resize: false,
                            scrollbar: false,
                            maxmin: false,//出现最大化按钮
                            content:$('#layer_window')
                        })
                    });

                }
            });
        }




        //提交表单
        $('.save-btn').on('click',function(){
            layer.confirm('确定要修改当前数据？', {
                btn: ['确定','取消'],title:'提示'
            }, function(){
                layer.closeAll();
                var index=layer.load();
                $.post('/sea/supply/produceDetail/usave.do',
                    {
                        id:$("#id").val(),
                        produceTotal:$("#produceTotal").val(),
                        producePrice:$("#producePrice").val(),
                        produceUnitPrice:$("#produceUnitPrice").val(),
                        produceTotal:$("#produceTotal").val(),
                        produceId:$("#produceId").val(),
                        buyId:$("#buyId").val()
                    },function(data){
                        if( data.ok ){
                            cur_table.bootstrapTable('refresh');
                            layer.msg(data.msg,{icon:1,time:1500,shade: [0.8, '#393D49']});
                            layer.close(index);
                        }else{
                            layer.msg(data.msg,{icon: 0,time:1500,shade: [0.8, '#393D49']});
                            layer.close(index);
                        }
                    });
            });
        });

        //提交表单
        $('.save-agreement-btn').on('click',function(){
            layer.confirm('一但修改无法取消,确定要修改当前数据？', {
                btn: ['确定','取消'],title:'提示'
            }, function(){
                layer.closeAll();
                var index=layer.load();
                $.post('/sea/supply/produce/usaveAgreement.do',
                    {
                        id:$("#agreementId").val(),
                        produceAgreement:$("#produceAgreement").val(),
                        produceAgreementFile:$("#produceAgreementFile").val(),
                        supplierDay:$("#supplierDay").val()
                    },function(data){
                        if( data.ok ){
                            $portTable.bootstrapTable('refresh');
                            layer.msg(data.msg,{icon:1,time:1500,shade: [0.8, '#393D49']});
                            layer.close(index);
                        }else{
                            layer.msg(data.msg,{icon: 0,time:1500,shade: [0.8, '#393D49']});
                            layer.close(index);
                        }
                    });
            });
        });

        function optFormatter2(value,row){
            var content ='';
            if(produceStatus==1 || produceStatus==4) {
                content += '<button class="edit-btn btn btn-xs btn-info" data-buy-id="' + row.buyId + '" data-produce-id="' + row.produceId + '" data-unit-price="' + row.produceUnitPrice + '" data-price="' + row.producePrice + '" data-total="' + row.produceTotal + '" data-sku="' + row.orderSku + '" data-val="' + row.id + '" title="修改"><i class="fa fa-edit"></i>  </button>';
            }
            return content;
        }


        //操作菜单
        function optFormatter(value,row){
            var content = '';
            if(row.produceStatus==1) {
                content += '<button class="pass-btn btn btn-xs btn-success" data-val-no="' + row.produceNo + '" data-val="' + row.id + '" title="提交审核"><i class="fa fa-check-square-o" aria-hidden="true"></i> 提交审核 </button>';
                // content += '&nbsp;<button class="del-btn btn btn-xs btn-danger" data-val-no="' + row.orderNo + '" data-val="' + row.id + '" title="删除"><i class="fa fa-trash-o"></i> 删除</button>';
            }
            if(row.produceStatus==2){
                content += '<button class="check-btn btn btn-xs btn-success" data-val-no="' + row.orderNo + '" data-val="' + row.id + '" title="审批"><i class="fa fa-check-square-o" aria-hidden="true"></i> 审批 </button>';
            }
            if(row.produceStatus==4){
                content += '<button class="pass-btn btn btn-xs btn-warning" data-val-no="' + row.produceNo + '" data-val="' + row.id + '" title="重新提交"><i class="fa fa-exclamation-triangle" aria-hidden="true"></i> 重新提交</button>';
                content += '&nbsp;<button class="del-btn btn btn-xs btn-danger" data-val-no="' + row.produceNo + '" data-val="' + row.id + '" title="作废"><i class="fa fa-times" aria-hidden="true"></i> 作废</button>';
            }
            if(row.produceStatus==31){
                content += '<button class="receive-btn btn btn-xs btn-success" data-val-no="' + row.produceNo + '" data-val="' + row.id + '" title="一键收货"><i class="fa fa-check-square-o" aria-hidden="true"></i> 一键收货 </button>';
                content += '&nbsp;<button class="close-btn btn btn-xs btn-danger" data-val-number="'+row.produceSurplus+'" data-val-no="' + row.produceNo + '" data-val="' + row.id + '" title="手工关闭"><i class="fa fa-times" aria-hidden="true"></i> 手工关闭 </button>';
            }
            if(row.produceStatus==3){
                content += '&nbsp;<button class="receive-close-btn btn btn-xs btn-danger" data-val-total="'+row.produceTotal+'" data-val-number="'+row.produceSurplus+'" data-val-no="' + row.produceNo + '" data-val="' + row.id + '" title="未收关闭"><i class="fa fa-times" aria-hidden="true"></i> 未收关闭 </button>';
            }
             // content += '&nbsp;<button class="pay-btn btn btn-xs btn-warning" data-val-no="' + row.produceNo + '" data-val="' + row.id + '" title="申请付款"><i class="fa fa-check-square-o" aria-hidden="true"></i> 申请付款 </button>';
            if(row.flag==0 && row.produceStatus!=1 && row.produceStatus!=2 && row.produceStatus!=4 && row.produceStatus!=5) {
                content += '&nbsp;<button class="pay-btn btn btn-xs btn-warning" data-val-no="' + row.produceNo + '" data-val="' + row.id + '" title="申请付款"><i class="fa fa-check-square-o" aria-hidden="true"></i> 申请付款 </button>';
            }
            // if(row.produceAgreement==null  || row.produceAgreement == '' || row.produceAgreementFile == null || row.produceAgreementFile =='') {
            //
            // }
            content += '&nbsp;<button class="send-btn btn btn-xs btn-success" data-day="'+row.supplierDay+'" data-val="' + row.id + '" title="修改合同"><i class="fa fa-check-square-o"></i> 修改合同</button>';
            content += '&nbsp;<button class="export-fl-btn btn btn-xs btn-warning" data-val="'+row.id+'" title="导出辅料"><i class="fa fa-download" aria-hidden="true"></i>导出辅料</button>';
            content += '&nbsp;<button class="export-fnsku-btn btn btn-xs btn-warning" data-val="'+row.id+'" title="导出产品标"><i class="fa fa-download" aria-hidden="true"></i>导出产品标</button>';
            if(row.produceStatus==3) {
                content += '&nbsp;<button class="rollback-btn btn btn-xs btn-danger" data-val-total="'+row.produceTotal+'"  data-val-no="' + row.produceNo + '" data-val="' + row.id + '" title="回滚至待采购"><i class="fa fa-times" aria-hidden="true"></i> 回滚 </button>';
            }
            content += '&nbsp;<button class="detail-btn btn btn-xs btn-default" data-val="'+row.id+'" title="查看记录"> 查看记录</button>';
            return content;
        }
        //END 表格配置
    });


    $('.search-btn').on('click',function(){
        $portTable.bootstrapTable('refresh', { url:'${ctxPath}/sea/supply/produce/findByCnd.do?'+$('#search-form').serialize() });
    });

    //提交表单
    $('.save-check-btn').on('click',function(){
        var produceStatus=$('input:radio:checked').val();
        layer.confirm('确定要审核当前数据？', {
            btn: ['确定','取消'],title:'提示'
        }, function(){
            layer.closeAll();
            var index=layer.load();
            $.post('/sea/supply/produce/usave.do',{produceStatus:produceStatus,id:$("#produce_id").val(),produceRemark:$("#produceRemark").val()},function(data){
                if( data.ok ){
                    $portTable.bootstrapTable('refresh');
                    layer.msg(data.msg,{icon:1,time:1500,shade: [0.8, '#393D49']});
                    layer.close(index);
                }else{
                    layer.msg(data.msg,{icon: 0,time:1500,shade: [0.8, '#393D49']});
                    layer.close(index);
                }
            });
        });
    });

    layui.use('upload', function(){
        var upload = layui.upload;
        var index=null;
        upload.render({
            elem: '#import-btn', //绑定元素,
            accept:'file',
            url: '/sea/physical/refusedTax/import/', //上传接口
            data:{},
            before:function () {
                index=layer.load(1, {
                    shade: [0.1,'#fff'] //0.1透明度的白色背景
                });
            }
            ,done: function(data){
                if( data.ok ){
                    layer.msg(data.msg,{icon: 1,time: 1500},function(){
                        //刷新页面
                        $("#produceAgreementFile").val(data.data);
                        layer.close(index);
                    });
                }else{
                    layer.msg(data.msg,{icon: 0,time: 5000},function () {
                        layer.close(index);
                    });

                }
            }
            ,error: function(){
                //请求异常回调
                layer.closeAll();
            }
        });
    });

    //提交表单
    $('.save-pay-btn').on('click',function(){
        var producePayment=$("#producePayment").val();
        if(producePayment=='' || producePayment==null){
            layer.msg("预付款不能为空！",{icon:1,time:1500,shade: [0.8, '#393D49']});
            return;
        }
        layer.confirm('确定要预付款当前数据？', {
            btn: ['确定','取消'],title:'提示'
        }, function(){
            layer.closeAll();
            var index=layer.load();
            $.post('/sea/supply/produce/usave.do',{id:$("#pay_produce_id").val(),producePayment:producePayment,flag:1},function(data){
                if( data.ok ){
                    $portTable.bootstrapTable('refresh');
                    layer.msg(data.msg,{icon:1,time:1500,shade: [0.8, '#393D49']});
                    layer.close(index);
                }else{
                    layer.msg(data.msg,{icon: 0,time:1500,shade: [0.8, '#393D49']});
                    layer.close(index);
                }
            });
        });
    });

    $('.export-btn').on('click',function () {
        var selDatas = $portTable.bootstrapTable('getSelections');
        if( selDatas.length == 0 ){
            layer.msg('请选择要导出的采购单',{icon: 0,shade: [0.8, '#393D49'],time: 1500});
        }else{
            var ids = [],names = [];
            $.each(selDatas,function(i,d){
                ids.push(d.id);
            });
            ids = ids.join(',');
            window.location.href='/sea/supply/produceDetail/export.do?ids='+ids;
        }
    });
</script>
</body>
</html>
